package com.imooc.dianping.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {//insert的时候需要填充的值
        this.strictInsertFill(metaObject, "createdAt", Date::new, Date.class);
        this.strictInsertFill(metaObject, "updatedAt", Date::new, Date.class);
    }

    @Override
    public void updateFill(MetaObject metaObject) {//update的时候需要填充的值
        this.strictUpdateFill(metaObject, "updatedAt", Date::new, Date.class); // 起始版本 3.3.3(推荐)
    }
}